package com.chebaohui.iqs.service.impl.deal.union.sdk;

import java.util.Properties;

import com.chebaohui.iqs.service.impl.deal.union.util.PayConsume;

/**
 * 配置文件
 * 
 * @author xielonghai
 *
 */
public class UnionConfig {

	/* 签名方式，证书方式固定01，请勿改动 */ // 配置文件acpsdk.signMethod
	public static String signMethod;

	// 默认配置的是UTF-8
	public static String encoding = "UTF-8";

	/* 报文版本号，固定5.1.0，请勿改动 */ // 配置文件acpsdk.version
	public static String version;

	/* 签名证书类型，固定不需要修改 */ // 配置文件acpsdk.signCert.type
	public static String certType;

	/** 磁道加密公钥模数. */ // 配置文件acpsdk.encryptTrackKey.modulus
	public static String modulus;

	/** 磁道加密公钥指数. */// 配置文件acpsdk.encryptTrackKey.exponent
	public static String encryptTrackKeyExponent;

	/** 安全密钥(SHA256和SM3计算时使用) */// 配置文件 acpsdk.secureKey
	public static String secureKey;

	/** 是否验证验签证书CN，除了false都验 */
	public static boolean ifValidateCNName;// #
											// 是否验证验签证书的CN，测试环境请设置false，生产环境请设置true。非false的值默认都当true处理。acpsdk.ifValidateCNName

	/** 是否验证https证书，默认都不验 */
	public static boolean ifValidateRemoteCert;

	static {
		init();
	}

	public static void init() {
		Properties pro = ReadProperties.getPropertiesFromPath(PayConsume.root_path + "acp_config.properties");
		if (null == pro) {
			signMethod = "01";
			version = "5.1.0";
			certType = "PKCS12";
			modulus = "";
			encryptTrackKeyExponent = "";
			secureKey = "";
			ifValidateCNName = true;
			ifValidateRemoteCert = false;
		} else {// pro.getProperty
			if (!UnionSign.isEmpty(pro.getProperty("acpsdk.signMethod")))
				signMethod = pro.getProperty("acpsdk.signMethod").trim();
			else
				signMethod = "01";

			if (!UnionSign.isEmpty(pro.getProperty("acpsdk.version")))
				version = pro.getProperty("acpsdk.version").trim();
			else
				version = "5.1.0";

			if (!UnionSign.isEmpty(pro.getProperty(ProKey.SDK_SIGNCERT_TYPE)))
				certType = pro.getProperty(ProKey.SDK_SIGNCERT_TYPE).trim();
			else
				certType = "PKCS12";

			if (!UnionSign.isEmpty(pro.getProperty("acpsdk.encryptTrackKey.modulus")))
				modulus = pro.getProperty("acpsdk.encryptTrackKey.modulus").trim();
			else
				modulus = "";

			if (!UnionSign.isEmpty(pro.getProperty("acpsdk.encryptTrackKey.exponent")))
				encryptTrackKeyExponent = pro.getProperty("acpsdk.encryptTrackKey.exponent").trim();
			else
				encryptTrackKeyExponent = "";

			if (!UnionSign.isEmpty(pro.getProperty("acpsdk.secureKey")))
				secureKey = pro.getProperty("acpsdk.secureKey").trim();
			else
				secureKey = "";

			if (!UnionSign.isEmpty(pro.getProperty("acpsdk.ifValidateCNName"))
					&& "false".equals(pro.getProperty("acpsdk.ifValidateCNName").trim()))
				ifValidateCNName = false;
			else
				ifValidateCNName = true;

			if (!UnionSign.isEmpty(pro.getProperty("acpsdk.ifValidateRemoteCert"))
					&& "true".equals(pro.getProperty("acpsdk.ifValidateRemoteCert").trim()))
				ifValidateRemoteCert = true;
			else
				ifValidateRemoteCert = false;

		}
	}
}
